<?php
function trace ($die = false)
{
	$debug = debug_backtrace();

	/*
	print "<pre>";
	print_r($debug);
	print "</pre>";
	*/
	$trace = array();

	$trace[] = "</table>";
	foreach ($debug as $item)
	{
		$args = array();

		foreach ($item['args'] as $arg)
		{
			if (is_array($arg))
			{
				$args[] = "array()";
			}
			elseif (is_numeric($arg))
			{
				$args[] = $arg;
			}
			elseif (is_string($arg))
			{
				$args[] = '"'.$arg.'"';
			}
			elseif (is_bool($arg))
			{
				$args[] = $arg === true ? "true" : "false" ;
			}
			elseif (empty($arg))
			{
				$args[] = '""';
			}
		}

		$trace[] = "<tr><td>".basename($item['file']).":".$item['line']." </td><td> ".$item['function']."(".implode(", ", $args).")</td></tr>";
	}
	$trace[] = "<table border=1><tr><td><h3>File</h3></td><td><h3>Action</h3></td></tr>";

	//array_shift($trace);
	$trace = implode("", array_reverse(array_filter($trace)));

	print $trace."<br />";

	if ($die)
	{
		die();
	}

}


?>